#include<iostream>
#include<stack>

using namespace std;

const int N = 1e5 + 10;
int a[N] , b[N] , n;
int main()
{
    int q; cin >> q;
    while(q--)
    {
        cin >> n;
        for(int i = 1;i <= n;i ++) cin >> a[i];
        for(int i = 1;i <= n;i ++) cin >> b[i];
        stack<int>st;
        int j = 1;
        for(int i = 1;i <= n;i ++)
        {
            st.push(a[i]);
            while(j <= n && st.size() && b[j] == st.top())
            {
                st.pop();
                j ++;
            }
        }
        if(st.empty()) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
    return 0;
}